<?php

/**
 * Date: 2018-1-5 14:04:15
 * Author: 王衍生
 * authorEmail: 50634235@qq.com
 */

 abstract class base_facades_facade
 {
     static public function instance()
     {
         return static::getFacadeRoot();
     }

     static public function getFacadeRoot()
     {
        if(is_object($object = static::getFacadeAccessor())) {
            return $object;
        }
        throw new RuntimeException(sprintf('Facade:%s need getFacadeAccessor method return object', get_class()));
     }

    static protected function getFacadeAccessor()
    {
		throw new RuntimeException("Facade does not implement getFacadeAccessor method.");
    }

    static public function __callStatic($method, $args)
    {
        $instance = static::instance();
        switch(count($args)) {
            case 0:
                return $instance->$method();
            case 1:
                return $instance->$method($args[0]);
            case 2:
                return $instance->$method($args[0], $args[1]);
            case 1:
                return $instance->$method($args[0], $args[1], $args[2]);
            case 1:
                return $instance->$method($args[0], $args[1], $args[2], $args[3]);
            default:
                return call_user_func_array([$instance, $method], $args);
        }
    }

 }